﻿using System;
using System.Net.Sockets;
using Domain.Entities;

namespace Domain.NetworkService
{
    public class TcpResult : NetworkTestResult
    {
        public TcpPorts Port { get; set; }
        public SocketError Info { get; set; }
        public override string ToString()
        {
            return String.Format("{0} {1} {2} {3} {4} {5}", VarDateTime, NetworkTestDescription.TCP, IP, Port, Status, Info);
        }
        public override void WriteToDB(string name)
        {
            DBWorker dbw = new DBWorker();
            Console.WriteLine(this.ToString());
            dbw.WriteTestResult(this, name);
        }

        public override string ToString(ToStringFormatArgs arg)
        {
            if (arg == ToStringFormatArgs.DetailedSurvey)
            {
                return String.Format("{0} {1}", Port, Status == ResultStatus.Success?"доступен":"не доступен: " + Info);
            }
            return String.Format("{0} {1} {2} {3} {4} {5}", VarDateTime, NetworkTestDescription.TCP, IP, Port, Status, Info);
        }
        
    }
}
